<?php
C_base::Dy('c.kefu.kfbase');
class user extends kfbase{
	
	var $_vpath='kefu/user/';  //定义调用模板所属一级文件夹
	function __construct(){
		parent::__construct();
		$this->title = '用户管理';
	}
/********************************************个人****************************************/
	function gr(){//个人-列表
		$this->xwnum = '';
		$this->rs = C_base::M('kefu.recruit')->user_ss(array('lx'=>0));
	}
	
	function gr_xiu(){//个人-修改页面
		if(@$this->_get('id')){
			$this->user = C_base::M('admin.recruit')->user_s(array('id'=>$this->_get('id'),'lx'=>0));
			if(@$this->user){
				$a = C_base::M('admin.recruit')->ubase_s(array('uid'=>$this->_get('id')));
				if(@$a){
					$this->user['sfzh'] = $a['sfzh'];					
				}
			}
		}
	}
	
	function gr_u(){//个人-修改
		extract($this->_post());
		$this->_is_html = 1;
		if(!@$id){
			exit('-1');
		}
		$user = C_base::M('admin.recruit')->user_s(array('id'=>$id,'lx'=>0));
		if(!@$user){
			exit('-2');
		}else{
			if(@$phone && !util::preg_phone($phone)){
				exit('-4');//手机格式错误
			}elseif(@$email && !util::preg_email($email)){
				exit('-5');//邮箱格式错误
			}elseif(@$sfzh && !util::preg_sfzh($sfzh)){
				exit('-6');//身份证号格式错误
			}
			$sz = array('phone'=>$phone,'jifen'=>$jf,'email'=>$email);
			$r1 = C_base::M('admin.recruit')->user_u(array('id'=>$id),$sz);
			if($r1 == '1'){
				$w = array('uid'=>$id);
				$u = array('sfzh'=>$sfzh);
				$pd = C_base::M('admin.recruit')->ubase_s($w);
				if($pd){
					$r2 = C_base::M('admin.recruit')->ubase_u($w,$u);
				}else{
					$c = array_merge($this->_post(),$w);
					$r2 = C_base::M('admin.recruit')->ubase_c($u);
				}
				if($r2 > 0){
					exit('cg');
				}else{
					exit('-3');//成功一部分
				}
			}else{
				exit('error');
			}
		}
	}
/********************************************企业****************************************/
	function qy(){//企业-列表
		$this->xwnum = '';
		$this->rs = C_base::M('admin.recruit')->qy_ss();
	}
	
	function qy_xx(){//企业-详细信息页面
		if(@$this->_get('id')){
			$this->r = C_base::M('admin.recruit')->qy_s(array('id'=>$this->_get('id')));
			if(@$this->r){
				$this->rs = C_base::M('admin.recruit')->qys_s(array('uid'=>$this->_get('id')));
			}else{
				$this->_cuowu('非法操作');
			}
		}else{
			$this->_cuowu('非法操作');
		}
	}
	
	function qy_xiu(){//企业-修改页面
		if(@$this->_get('id')){
			$this->r = C_base::M('admin.recruit')->qys_s(array('uid'=>$this->_get('id')));
		}else{
			$this->_cuowu('非法操作');
		}
	}
	
	function qy_u(){//企业-修改
		extract($this->_post());
		$this->_is_html = 1;
		$w = array('uid'=>$uid);
		$u = array('email'=>$email);
		$r = C_base::M('admin.recruit')->qys_u($w,$u);
		if($r == '1'){
			exit('cg');
		}else{
			exit('error');
		}
	}
	
	function qy_cz(){//企业-充值
		$this->id = $this->_get('id');
	}
	
	function qy_czmm(){//企业-重置密码
		extract($this->_post());
		$w = array('id'=>$id);
		$u = array('pass'=>md5(111111));
		$r = C_base::M('admin.recruit')->qy_u($w,$u);
		if($r == '1'){
			exit('cg');
		}else{
			exit('error');
		}
	}
/********************************************专家****************************************/
	function zj(){//专家-列表
		$this->xwnum = '';
		$this->rs = C_base::M('admin.recruit')->user_ss(array('lx]'=>1,'lx|'=>2));
	}
	
	function zj_xiu(){//专家-修改页面
		$this->tit ='专家编辑';
		$this->user = C_base::M('admin.recruit')->user_s(array('id'=>@$this->_get('id')));
		if($this->user['lx'] == 1){  //普通专家
			$this->user['base'] = C_base::M('admin.recruit')->ubase_s(array('uid'=>$this->_get('id')));
		}elseif($this->user['lx'] == 2){  //vip专家
			$this->user['base'] = C_base::M('admin.recruit')->vbase_s(array('uid'=>$this->_get('id')));
		}else{
			$this->_cuowu('问题账号');
		}
	}
	
	function zj_u(){//专家-修改
		extract($this->_post());
		$this->_is_html = 1;
		$w1 = array('id'=>$id);
		$w2 = array('uid'=>$id);
		$u1 = array('email'=>$email,'phone'=>$phone,'jifen'=>$jf);
		$u2 = array('name'=>$name,'sfzh'=>$sfz);
		$this->user = C_base::M('admin.recruit')->user_s($w1);
		if($phone){
			$uu = C_base::M('admin.recruit')->user_s(array('id!'=>$id,'phone'=>$phone));
			if($uu){
				exit('-2');//此手机号已存在
			}
		}
		if($email){
			$ss = C_base::M('admin.recruit')->user_s(array('id!'=>$id,'email'=>$email));
			if($ss){
				exit('-3');//此邮箱已存在
			}
		}
		$r1 = C_base::M('admin.recruit')->user_u($w1,$u1);
		if($r1){
			if($this->user['lx'] == 1){  //普通专家
				$r2 = C_base::M('admin.recruit')->ubase_u($w2,$u2);
			}elseif($this->user['lx'] == 2){  //vip专家
				$r2 = C_base::M('admin.recruit')->vbase_u($w2,$u2);
			}
			if($r2 == '1'){
				exit('cg');
			}else{
				exit('-1');//部分数据修改成功
			}
		}else{
			exit('error');
		}
	}

	function czimg(){
		extract($this->_post());
		$w = array('uid'=>$id);
		$u = array('touxiang'=>'92_1');
		if($type == 1){//普通专家或用户
			$r = C_base::M('admin.recruit')->ubase_u($w,$u);
		}else if($type == 2){//VIP专家
			$r = C_base::M('admin.recruit')->vbase_u($w,$u);
		}
		if($r == 1){
			exit('cg');
		}else{
			exit('error');
		}
	}
	
	function sjvip(){
		extract($this->_post());
		$w = array('id'=>$id);
		$a = C_base::M('admin.recruit')->user_s($w);
		if($a['lx'] == 2){
			exit('-1');//该专家已经是VIP专家
		}
		$u = array('lx'=>2);
		$b = C_base::M('admin.recruit')->user_u($w,$u);
		if($b){
			$w1 = array('uid'=>$id);
			$r = C_base::M('admin.recruit')->ubase_s($w1);
			if($r){
				$c = array('uid'=>$r['uid'],'touxiang'=>$r['touxiang'],'name'=>$r['name'],'sex'=>$r['sex'],'minzu'=>$r['minzu'],'cstime'=>$r['cstime'],
						'xsheng'=>$r['xsheng'],'xshi'=>$r['xshi'],'xqu'=>$r['xqu'],'xsq'=>$r['xsq'],'sfzh'=>$r['sfzh'],'byyx'=>$r['byyx']);
				$r2 = C_base::M('admin.recruit')->vbase_c($c);
			}
			exit('cg');
		}else{
			exit('error');
		}
	}
	
	function jv(){
		extract($this->_post());
		$w = array('id'=>$id);
		$r = C_base::M('admin.recruit')->user_u($w,array('vlevel'=>$type));
		if($r == 1){
			exit('cg');
		}else{
			exit('error');
		}
	}
}
/*********************************************************************文件已结束*****************************************************************/